package orthoplanner.com.google.code.ui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import orthoplanner.com.google.code.eventhandlers.AddCircleHandler;
import orthoplanner.com.google.code.eventhandlers.AddLineHandler;
import orthoplanner.com.google.code.eventhandlers.AdvanceHandler;
import orthoplanner.com.google.code.eventhandlers.ClearAllListener;
import orthoplanner.com.google.code.eventhandlers.ClearAnglesHandler;


public class LineControlPanel extends JPanel {
	private static final long serialVersionUID = -5700618211321555635L;
	private JButton bAddLine, bAddCircle, bClearAngles,bClearAll,bAdvance;
	private static JCheckBox freeze;

	public LineControlPanel(ImageViewer imgViewer) {
		setFont( new Font("SansSerif", Font.BOLD, 12));
		bAddLine = new JButton("Add Line");
		bAdvance = new JButton("Advance");
		bClearAll = new JButton("Clear All");
		bAddLine.setFont( new Font("SansSerif", Font.BOLD, 12));
		bAdvance.setFont( new Font("SansSerif", Font.BOLD, 12));
		bClearAll.setFont( new Font("SansSerif", Font.BOLD, 12));
		bAddCircle = new JButton("Add Circle");
		bAddCircle.setFont( new Font("SansSerif", Font.BOLD, 12));;
		bClearAngles = new JButton("Clear Angles");
		freeze = new JCheckBox("Freeze controls");
		freeze.setFont( new Font("SansSerif", Font.BOLD, 12));
		bAddLine.setPreferredSize(new Dimension(120, 30));
		bAddCircle.setPreferredSize(new Dimension(120, 30));
		bClearAngles.setPreferredSize(new Dimension(120, 30));
		bAdvance.setPreferredSize(new Dimension(120, 30));
		bClearAll.setPreferredSize(new Dimension(120, 30));
		
		bClearAngles.setFont( new Font("SansSerif", Font.BOLD, 12));
		setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;

		gbc.anchor = GridBagConstraints.CENTER;
		add(bAddLine, gbc);
		gbc.gridy = 1;
		add(bAddCircle, gbc);
		gbc.gridy = 2;
		add(bAdvance, gbc);
		gbc.gridy = 3;
		add(bClearAngles, gbc);
		gbc.gridy = 4;
		add(bClearAll, gbc);
		gbc.gridy = 5;
		add(freeze, gbc);

		setBorder(new TitledBorder("Controls"));
		bAddLine.addMouseListener(new AddLineHandler(imgViewer));
		bAddCircle.addMouseListener(new AddCircleHandler(imgViewer));
		bClearAngles.addMouseListener(new ClearAnglesHandler(imgViewer));
		bClearAll.addMouseListener(new ClearAllListener(imgViewer));
		bAdvance.addMouseListener(new AdvanceHandler(imgViewer));
		freeze.setSelected(true);
	}

	public static boolean isFreezed() {
		return freeze.isSelected();
	}
}
